import {
	postExamLogin
} from "."
import {
	iceSetStorage
} from "../../utils/common"
import {
	setGetAllData
} from '@/src/utils/icePinia';
import {
	postHandExamPage
} from '../../src/api';
const submitData = setGetAllData().submitData
// 交卷
export const postHandExamPages = (msgParams, force = false) => {
	submitData.status = 3
	postHandExamPage(submitData).then(res => {
		if (res.code == 0) {
			msgParams.value = {
				msgType: 's',
				messageText: force ? '考试时间到，自动交卷' : res.msg,
				isOpen: true
			}
			iceSetStorage('iceCheckCheat', false)
			setTimeout(() => {
				uni.navigateTo({
					url: '/pages/kaoshiPre/index'
				})
			}, 1000)
		}
	})
}
// 辅助函数
const msgParamsHandle = (msgParams, msgInfo) => {
	const {
		popupType,
		msgType,
		messageText
	} = msgInfo
	msgParams.value = {
		popupType: popupType,
		msgType: msgType,
		messageText: messageText,
		isOpen: true
	}
}
export const postExamLogins = (bool, form, msgParams, msgParams2, uid, show) => {
	let msgInfo = {}
	postExamLogin(form).then(res => {
		iceSetStorage('userId', res.data.uid)
		iceSetStorage('username', form.username)
		iceSetStorage('password', form.password)
		uid.value = res.data.uid
		if (res.data.reg_pwd == '不修改') {
			// if (res.data.reg_pwd == '不修改') {
			msgInfo = {
				popupType: 'message',
				msgType: 's',
				messageText: res.msg,
			}
			let clear = setTimeout(() => {
				clearTimeout(clear)
				// uni.redirectTo({
				uni.navigateTo({
					url: `/pages/kaoshiPre/index`
				})
			}, 1000)
			msgParamsHandle(msgParams, msgInfo)
			show.value = false
		} else {
			show.value = false
			msgInfo = {
				title: '修改密码',
				placeholder: '请输入新密码',
				isOpen: true
			}
			msgParams2.value = msgInfo
		}
	}).catch(error => {
		msgInfo = {
			popupType: 'message',
			msgType: 'e',
			messageText: error,
		}
		show.value = false
		msgParamsHandle(msgParams, msgInfo)
	})
}